<template>
  <div class="member-order-detail" v-if="order">
    <!-- 头部 -->
    <DetailAction :order="order" />
    <!-- 进度 -->
    <DetailStep :order="order" />
    <!-- 物流 -->
    <Suspense>
      <!-- 异步加载完后加载 -->
      <template #default>
        <DetailLogistics v-if="[3,4,5].includes(order.orderState)" :order="order" />
      </template>
      <!-- 等待异步加载中显示 -->
      <template #fallback>
        <div class="loading">loading...</div>
      </template>
    </Suspense>
    <!-- 订单信息 -->
    <DetailInfo :order="order" />
  </div>
</template>

<script>
import DetailAction from '@/views/member/order/components/detail-action.vue'
import { findOrderDetail } from '@/api/order'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import DetailStep from '@/views/member/order/components/detail-step.vue'
import DetailLogistics from './components/detail-logistics.vue'
import DetailInfo from './components/detail-info.vue'

export default {
  name: 'MemberOrderDetail',
  components: {
    DetailAction,
    DetailStep,
    DetailLogistics,
    DetailInfo
  },
  setup() {
    const order = ref(null)
    const route = useRoute()
    findOrderDetail(route.params.id).then(data => {
      order.value = data.result
    })
    return { order }
  }
}
</script>

<style scoped lang="less">
.member-order-detail {
  background-color: #fff;
  height: 100%;

  .loading {
    height: 50px;
    display: flex;
    align-items: center;
    padding: 0 30px;
    background-color: #f5f5f5;
    margin: 30px 50px 0;
    color: #999;
  }
}
</style>
